// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-20 19:08
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.ACWing.DataTrains.DesingSki;

import java.util.Scanner;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner myScanner = new Scanner(System.in);
        int n = myScanner.nextInt(), ans = Integer.MAX_VALUE, cost = 0;
        int[] mh = new int[n];
        for (int i = 0; i < n; ++i) {
            mh[i] = myScanner.nextInt();
        }
        for (int i = 0; i + 17 <= 100; i++) {
            int r = i + 17;
            for (int j = 0; j < n; j++) {
                if (mh[j] < i) {
                    cost += (i - mh[j]) * (i - mh[j]);
                } else if (mh[j] > r) {
                    cost += (mh[j] - r) * (mh[j] - r);
                }
            }
            ans = Math.min(ans, cost);
            cost = 0;
        }
        System.out.print(ans);

    }
}
